package com.zlp.oauth.config;

import com.zlp.oauth.hancer.MyTokenEnhancer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @author LiPing.Zou
 * @since 1.0.0
 */
@Configuration
public class JwtTokenConfig {

	/**
	 * 秘钥
	 */
	@Value("${jwt.secret}")
	private String secret;


	@Bean("jwtTokenStore")
	public TokenStore jwtTokenStore(){
		return new JwtTokenStore(jwtTokenConverter());
	}

	@Bean("jwtTokenConverter")
	public JwtAccessTokenConverter jwtTokenConverter(){

		JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
		// 设置秘钥
		jwtAccessTokenConverter.setSigningKey(secret);
		return jwtAccessTokenConverter;
	}

	/**
	 * token 增强剂
	 * @date: 2021/3/30 15:48
	 * @return: org.springframework.security.oauth2.provider.token.TokenEnhancer
	 */
	@Bean("tokenEnhancer")
	public TokenEnhancer tokenEnhancer (){
		return new MyTokenEnhancer();
	}

}